package database

// 指令集合
var cmdKeyExecutorMap map[string]*CmdExecutor

// 指令执行器函数结构体
type CmdExecutor struct {
	// 指令执行函数
	cmdExecuteFun CmdExecFun
	cmdPreFun     PreFun
	undoFun       UndoFun
	// 指令应该的参数个数
	arity int
	// 读写标记
	rwFlag int
	// 指令AOF标记
	aofWrite bool
}

func init() {
	cmdKeyExecutorMap = make(map[string]*CmdExecutor)
}

// 指令注册
func RegisterDBCmd(cmd string, cmdExecuteFun CmdExecFun, cmdPreFun PreFun, undoFun UndoFun, arity int, rwFlag int, aofWrite bool) {
	databaseCmdPtr := &CmdExecutor{
		cmdExecuteFun: cmdExecuteFun,
		cmdPreFun:     cmdPreFun,
		undoFun:       undoFun,
		arity:         arity,
		rwFlag:        rwFlag,
		aofWrite:      aofWrite,
	}
	cmdKeyExecutorMap[cmd] = databaseCmdPtr
}
